<template>
  <section id="article">
    <header class="header"
            @click="info">
      <h2 class="title">{{title}}</h2>
      <span class="time">
        <i class="iconfont">&#xe6ce;</i>
        {{item.createdAt}}
      </span>
    </header>
    <section class="content">
      <p>{{content}}</p>
    </section>
    <footer class="footer">
      <div class="menu"><i class="iconfont">&#xe603;</i> 点赞{{item.follow}}</div>
      <span class="bar">|</span>
      <div class="menu"><i class="iconfont">&#xe625;</i> 评论</div>
      <span class="bar">|</span>
      <div class="menu"><i class="iconfont">&#xe65c;</i> 分享</div>
    </footer>
  </section>
</template>

<script>
export default {
  props: ["item"],
  data() {
    return {
      title: "",
      content: "",
    };
  },
  mounted() {
    let reg = new RegExp("(?<=>).+(?=<)", "g");
    this.title = reg.exec(this.item.content)[0];
    for (let i = 0; i <= 10; i++) {
      this.content += reg.exec(this.item.content)[0];
    }
  },
  methods: {
    info() {
      this.$router.push({
        name: "info",
        params: { content: this.item.content },
      });
    },
  },
};
</script>

<style lang="less" scoped>
#article {
  width: calc(100% - 40px);
  height: 200px;
  box-sizing: border-box;
  padding: 0 16px;
  margin: 0 auto 10px;
  border: 1px solid #eaecef;
  transition: all 0.2s linear;
  position: relative;
  cursor: pointer;

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eaecef;
    margin-bottom: 16px;

    .title {
      width: 70%;
      margin-top: 16px;
      padding: 0 0 7.2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 20px;
    }
    .time {
      font-size: 12px;
      display: inline-block;
      vertical-align: bottom;
    }
  }

  .content {
    p {
      margin: 0 auto;
      width: 80%;
      overflow: hidden;
      line-height: 1.6;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      text-align: justify;
    }
  }

  .footer {
    width: 96%;
    height: 30px;
    box-sizing: border-box;
    position: absolute;
    bottom: 0;
    border-top: 1px solid #eaecef;

    .menu {
      display: inline-block;
      text-align: center;
      width: 32%;
      font-size: 12px;
    }
    .bar {
      color: #eaecef;
    }
  }
}
#article:hover {
  box-shadow: 1px 1px 3px 3px #eaecef;
}
</style>